﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net.Sockets;
using System.IO;

namespace SocketClient
{
    /// <summary>
    /// Interaction logic for criarsala.xaml
    /// </summary>
    public partial class criarsala : Window
    {
        private Conexao conexao;

        public criarsala(Conexao con)
        {
            this.conexao = con;

            InitializeComponent();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                String txt = textBox1.Text;
                //writer.WriteLine("criarsala    " + txt); //envia msg ao servidor
                conexao.Send("criarsala/" + txt);
                //String resposta = reader.ReadLine();
                String resposta = conexao.Receive();
                String[] tokens = resposta.Split('|');
                if (txt == tokens[0])
                {
                    salinha sa = new salinha(conexao, tokens[1], tokens[0]);
                    Close();
                    sa.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Resposta do servidor: " + resposta);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
        }
    }
}
